home *** CD-ROM | disk | FTP | other *** search
- Path: nic.wat.hookup.net!news
- From: xenon@the-fix.sos.on.ca
- Newsgroups: comp.lang.c
- Subject: Re: Question!@#!
- Date: Tue, 23 Jan 1996 22:42:08 GMT
- Organization: HookUp Communication Corporation, Waterloo, Ontario, CANADA
- Message-ID: <4e3p30$off@nic.wat.hookup.net>
- References: <4dcejq$2un@venus.senecac.on.ca>
- NNTP-Posting-Host: slip5.sos.on.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- cweselak@learn.senecac.on.ca (Christian Weselak) wrote:
-
-
- >I have a very Simple question.. well, it should be simple for 'alot' of
- >you reading this newsgroup..
-
- >anyways.
-
- >I have created a program that asks THE users for his name, then writes it
- >to a file, the file is called name.txt..
-
- >Evertime this program is executed, the file name.txt get's overwritten.
-
- >How can i keep this file, name.txt, so that i can eventually have a
- >listing of all users who ran my program???
-
- >Appreciated..
-
- Hi. Your problem lies in the mode your using for fopen(). Your most
- likely using the mode "w" instead of "a" Try this:
-
- include <stdio.h>
- include <conio.h>
-
- main()
- {
- FILE *fp;
- char name[20];
- puts("Enter your name: \n");
- gets(name);
- fp=fopen("names.txt","a") /* append instead of write..should test
- for occurrence of error from fopen :>*/
- fprintf(fp,"%s",name);
- fclose(fp);
- }
-
- Hope this helps...
-
- xenon@sos.on.ca
-
-
-
-